<?php
/**
 * Template Name:Custom Login
 */

global $user_ID;
global $wpdb;

##下面只是大框架的模板，具体到错误返回信息的这种的话要用到ajax。 表格的样式也需要自己调，用bootstrap的话会更好点
if (!$user_ID) {
  # user in logged out status
  if ($_POST) {
    # 这些数据要通过wp signon 提取的，所以要用esc_sql ? 
    $username = esc_sql($_POST['username']);
    $password = esc_sql($_POST['password']);

    $login_array = array();
    $login_array['user_login'] = $username;
    $login_array['user_password'] = $password;

    $verify_user = wp_signon($login_array, true); 
    #check if an erroe object or what 
    if (!is_wp_error($verify_user)) {
      # code...

      echo "<script>window.location = '" . home_url('/') . "'</script>";
    } else {
      echo "登陆信息不正确，请重新输入";
    }

  } else { 
   get_header();
  ?>
  <div class="container clearfix pt-3">
  <form method="post">
    <p>
      <label for="username">Username/Email</label>
      <input type="text" name="username" id="username" placeholder="Enter Username">
    </p>
    <p>
      <label for="password">Password</label>
      <input type="password" name="password" id="password" placeholder="Enter Password">
    </p>
    <p>
      <button type="submit" name="btn_submit">Log In</button>
    </p>
  </form>
  </div>

<?php
  get_footer();
 
  }

} else {
  #user is logged in 
  echo "<script>window.location = '" . home_url('/') . "'</script>";


}